package com.seckill.controller;

import com.seckill.entity.Result;
import com.seckill.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangzhilong
 * @date 2019-06-18
 */
@RestController
public class SeckillController {

    @Autowired
    private SeckillService seckillService;

    @PostMapping("/seckill")
    public Result seckill(){
        try {
            int v = (int)(Math.random() * 10);
            int bookId = v >= 5 ? 2 : 1;
            return seckillService.seckill(bookId);
        } catch (Exception e) {
            System.err.println(e.getMessage());
            return Result.ERROR(e.getMessage());
        }
    }

}
